package com.maya.medicalwastes.adapter;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.maya.medicalwastes.CollectActivity;
import com.maya.medicalwastes.DoctorActivity;
import com.maya.medicalwastes.LoginActivity;
import com.maya.medicalwastes.R;
import com.maya.medicalwastes.RelationActivity;
import com.maya.medicalwastes.ScaleActivity;
import com.maya.medicalwastes.WareHouseActivity;
import com.maya.medicalwastes.dialog.CommonMsgDialog;
import com.maya.medicalwastes.entity.CloseEvent;
import com.maya.medicalwastes.entity.MenuEntity;
import com.maya.medicalwastes.httpNet.common.SharedPreferencesConstant;
import com.maya.medicalwastes.ui.BarcodeActivity;
import com.maya.medicalwastes.ui.InWareHousetActivity;
import com.maya.medicalwastes.ui.OutputActivity;
import com.maya.medicalwastes.ui.TodayCollectActivity;
import com.maya.medicalwastes.ui.WarehouseActivity;
import com.maya.medicalwastes.util.MyUtils;
import com.maya.medicalwastes.util.PrefUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * @author created by fuguoyong
 * 版本：1.0
 * 创建日期：2020-11-19 14
 * 描述：SecondMenuAdapter
 */
public class SecondMenuAdapter extends BaseQuickAdapter<MenuEntity, BaseViewHolder> {
    public SecondMenuAdapter(int layoutResId, @Nullable List<MenuEntity> data) {
        super(layoutResId, data);
    }

    private closeClick mCloseClick;

    public void setCloseClick(closeClick click) {
        this.mCloseClick = click;

    }

    public interface closeClick {
        void close();
    }

    private AlertDialog mAlertDialog;

    @Override
    protected void convert(BaseViewHolder helper, MenuEntity item) {
        helper.setText(R.id.tv_title, item.getMenuName());
        helper.setOnClickListener(R.id.view_menu, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (item.getTag().equals("app.medicalWaste.todayCollect")) {
                    MyUtils.IntentToOther(mContext, TodayCollectActivity.class, null);
                } else if (item.getTag().equals("app.medicalWaste.collect")) {
                    Bundle bundle = new Bundle();
                    bundle.putString("type", "1");
                    MyUtils.IntentToOther(mContext, DoctorActivity.class, bundle);
                } else if (item.getTag().equals("app.medicalWaste.warehousing")) {
                    Bundle bundle = new Bundle();
                    bundle.putString("type", "1");
                    MyUtils.IntentToOther(mContext, WareHouseActivity.class, bundle);
                } else if (item.getTag().equals("app.medicalWaste.weighTest")) {
                    //电子秤
                    MyUtils.IntentToOther(mContext, ScaleActivity.class, null);
                    //箱代关联
                } else if (item.getTag().equals("app.medicalWaste.binding")) {
                //    MyUtils.IntentToOther(mContext, RelationActivity.class, null);
                } else if (item.getTag().equals("app.medicalWaste.warehouseOut")) {
                    Bundle bundle = new Bundle();
                    bundle.putString("type", "2");
                    MyUtils.IntentToOther(mContext, WareHouseActivity.class, bundle);
                    //当前库存
                } else if (item.getTag().equals("app.medicalWaste.currentStock")) {
                    Bundle bundle = new Bundle();
                    bundle.putString("type", "3");
                    MyUtils.IntentToOther(mContext, InWareHousetActivity.class, bundle);
                    //出库单（今日）
                } else if (item.getTag().equals("app.medicalWaste.outboundOrder")) {
                    Bundle bundle = new Bundle();
                    bundle.putString("type", "5");
                    MyUtils.IntentToOther(mContext, InWareHousetActivity.class, bundle);
                } else if (item.getTag().equals("app.medicalWaste.generateQRcode")) {
                        MyUtils.IntentToOther(mContext, BarcodeActivity.class, null);
                } else if (item.getTag().equals("app.medicalWaste.logout")) {
                    mAlertDialog = new AlertDialog.Builder(mContext)
                              .setMessage("请确认退出吗？")
                              .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                  public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {
                                      EventBus.getDefault().post(new CloseEvent());
                                  }
                              }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(DialogInterface dialogInterface, int i) {
                                      mAlertDialog.dismiss();
                                  }
                              })
                              .create();
                    mAlertDialog.setCanceledOnTouchOutside(false);
                    mAlertDialog.show();
                    //   MyUtils.IntentToOther(mContext, WarehouseActivity.class, null);
                } else {

                    //   MyUtils.IntentToOther(mContext, ScaleActivity.class, null);

                }
            }
        });
        initIcons(helper, item.getTag());
    }

    private void initIcons(BaseViewHolder viewHolder, String tag) {
        if (tag.equals("app.medicalWaste.todayCollect")) {
            //运送管理-任务列表
            viewHolder.setImageResource(R.id.iv_icon_new, R.drawable.icon_jinrishouji);
        } else if (tag.equals("app.medicalWaste.collect")) {
            viewHolder.setImageResource(R.id.iv_icon_new, R.drawable.icon_shouji);
        } else if (tag.equals("app.medicalWaste.warehousing")) {
            viewHolder.setImageResource(R.id.iv_icon_new, R.drawable.icon_warehousing);
        } else if (tag.equals("app.medicalWaste.weighTest")) {
            viewHolder.setImageResource(R.id.iv_icon_new, R.drawable.icon_dianzichengtiaoshi);
        } else if (tag.equals("app.medicalWaste.binding")) {
            viewHolder.setImageResource(R.id.iv_icon_new, R.drawable.icon_xiangdaiguanlian);
        } else if (tag.equals("app.medicalWaste.warehouseOut")) {
            viewHolder.setImageResource(R.id.iv_icon_new, R.drawable.icon_ruku);
        } else if (tag.equals("app.medicalWaste.currentStock")) {
            viewHolder.setImageResource(R.id.iv_icon_new, R.drawable.icon_dangqiankucun);
        } else if (tag.equals("app.medicalWaste.outboundOrder")) {
            viewHolder.setImageResource(R.id.iv_icon_new, R.drawable.icon_chukudan_jinri);
        } else if (tag.equals("app.medicalWaste.generateQRcode")) {
            viewHolder.setImageResource(R.id.iv_icon_new, R.drawable.icon_warehousing);
        } else if (tag.equals("app.medicalWaste.logout")) {
            viewHolder.setImageResource(R.id.iv_icon_new, R.drawable.icon_tuichu);
        }
    }


}
